using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;

namespace ERP.Classes
{
	/// <summary>
	/// Summary description for csDataGrid.
	/// </summary>
	public class csDataGrid
	{
		
		public csDataGrid()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		public int CreateTableStyle(string TableName,DataGrid grid,DataSet ds, string[] Header, string[] MappingName,int[] ColWidth)
		{
			//grid.Collapse(-1);
//			if(ds == null || ds.Tables[0].Rows.Count == 0)
//			{
//				grid.DataSource=ds.Tables[0];
//				grid.Refresh();
//				return 0;
//			}
														 
			try
			{
				grid.DataSource=ds.Tables[0];

				DataGridTableStyle grdTableStyle1 = new DataGridTableStyle();
				grdTableStyle1.AlternatingBackColor = Color.GhostWhite;
				grdTableStyle1.BackColor = Color.WhiteSmoke;
				grdTableStyle1.ForeColor = Color.Black;
				grdTableStyle1.GridLineColor = Color.Tomato;
				grdTableStyle1.HeaderBackColor = Color.ForestGreen;
				grdTableStyle1.HeaderFont = new Font("Tahoma", (float) 10.0, FontStyle.Bold);
				grdTableStyle1.HeaderForeColor = Color.White;
				grdTableStyle1.SelectionBackColor = Color.Coral;
				grdTableStyle1.SelectionForeColor = Color.DarkRed;

				// Do not forget to set the MappingName property. 
				// Without this, the DataGridTableStyle properties
				// and any associated DataGridColumnStyle objects
				// will have no effect.

				grdTableStyle1.MappingName = ds.Tables[0].TableName;
				grdTableStyle1.PreferredColumnWidth = 125;
				grdTableStyle1.PreferredRowHeight = 20;
				for (int i=0;i<Header.GetLength(0);i++)
				{
					DataGridTextBoxColumn grdColStyle1 = new DataGridTextBoxColumn();

					grdColStyle1.HeaderText = Header[i];
				
					grdColStyle1.MappingName = MappingName[i];
				
					grdColStyle1.Width = ColWidth[i];
					grdTableStyle1.GridColumnStyles.Add(grdColStyle1);
				}
				grid.TableStyles.Clear();
				grid.TableStyles.Add(grdTableStyle1);
				return ds.Tables[0].Rows.Count;
			}
			catch
			{
				return 0;
			}
			
		}

		public int CreateTableStyle(string TableName,DataGrid grid,DataSet ds, string[] Header, string[] MappingName,int[] ColWidth,int numColDisable)
		{
			//grid.Collapse(-1);
//			if(ds == null || ds.Tables[0].Rows.Count == 0)
//			{
//				grid.DataSource=ds.Tables[0];
//				grid.Refresh();
//				return 0;
//			}

			try
			{
				grid.DataSource=ds.Tables[0];

				DataGridTableStyle grdTableStyle1 = new DataGridTableStyle();
				grdTableStyle1.AlternatingBackColor = Color.GhostWhite;
				grdTableStyle1.BackColor = Color.WhiteSmoke;
				grdTableStyle1.ForeColor = Color.DarkGreen;
				grdTableStyle1.GridLineColor = Color.Tomato;
				grdTableStyle1.HeaderBackColor = Color.ForestGreen;
				grdTableStyle1.HeaderFont = new Font("Tahoma", (float) 10.0, FontStyle.Bold);
				grdTableStyle1.HeaderForeColor = Color.White;
				grdTableStyle1.SelectionBackColor = Color.Coral;
				grdTableStyle1.SelectionForeColor = Color.DarkRed;
				

				// Do not forget to set the MappingName property. 
				// Without this, the DataGridTableStyle properties
				// and any associated DataGridColumnStyle objects
				// will have no effect.

				grdTableStyle1.MappingName = ds.Tables[0].TableName;
				grdTableStyle1.PreferredColumnWidth = 125;
				grdTableStyle1.PreferredRowHeight = 20;
				for (int i=0;i<Header.GetLength(0);i++)
				{
					DataGridTextBoxColumn grdColStyle1 = new DataGridTextBoxColumn();

					grdColStyle1.HeaderText = Header[i];
				
					grdColStyle1.MappingName = MappingName[i];
				
					grdColStyle1.Width = ColWidth[i];
					grdTableStyle1.GridColumnStyles.Add(grdColStyle1);
				}
				grid.TableStyles.Clear();
				grid.TableStyles.Add(grdTableStyle1);
				this.DisableColumn(grid,numColDisable);
				return ds.Tables[0].Rows.Count;
			}
			catch
			{
				return 0;
			}
			
		}

		public void DisableColumn(DataGrid grid,int i)
		{
			for (int k=0;k<i;k++)
			{
				grid.TableStyles[0].GridColumnStyles[k].ReadOnly=true;
			}
			//grid.TableStyles[0].c[0].vi=true;
		}
	}
}
